﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Diagnostics.Tracing;
using Architecture.CrossCutting.RepositoryPattern.Logging;

namespace Architecture.CrossCutting.RepositoryPattern.Logging.ETW
{
    public class ETWLogParser
    {

        public static ETWLogParser Current = new ETWLogParser();

        public EFLog CreateFromEventDbQuery(TraceEvent data)
        {
            return new EFLog()
            {
                LogId = Guid.NewGuid(),
                CorrelationId = data.ActivityID,
                EventIndex = (int)data.EventIndex,
                EventName  =data.EventName,
                Level = data.Level.ToString(),
                Operation = data.OpcodeName,
                TaskName = data.TaskName,
                ThreadId = data.ThreadID,
                ProcessId = data.ProcessID,
                Query = (String)data.PayloadByName("query"),
                commandType = (String)data.PayloadByName("commandType"),
                ExecutionTime = (Int64)data.PayloadByName("executionTime")
            };
        }
    }
}
